<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<title>微信支付页</title>
        <link rel="icon" href="./img/favicon.ico">
		
	
  <!--  <link rel="stylesheet" type="text/css" href="./css/all.css" />
    <link rel="stylesheet" type="text/css" href="./css/pages-weixinpay.css" />-->
</head>

<body>

<div id="app">
		<!--head-->

		<div >
			<h1>收银台</h1>
			<!--主内容-->
			<h4 class="checkout py-container  pay">
				<div>
					<h4>订单提交成功，请您及时付款！订单号：{{orderId}}</h4>
                    <!--<h4>应付金额：</em>￥{{(money/100).toFixed(2)}}</em>元</h4>-->
                    <h4>应付金额：</em>￥{{money}}</em>元</h4>
				</div>
				<hr>
					<h4>微信支付</h4>

                        <p class="red">二维码已过期，刷新页面重新获取二维码。</p>                      
                        <div class="fl code">
                            <div id="qrcode"></div>
                            <div >
                                <p>请使用微信扫一扫</p>
                                <p>扫描二维码支付</p>
                            </div>
                        </div>

                        


			</div>

		</div>
		<!-- 底部栏位 -->
		<!--页面底部-->

<!--页面底部END-->
</div>

<script src="../js/vue.js"></script>
<script src="../js/axios.min.js"></script>
<script src="../js/qrcode.min.js"></script>
<script src="../js/util.js"></script>
<script src="../js/stomp.min.js"></script>
<script>

	new Vue({
		el:'#app',
		data(){
		    return {
		        orderId:'',
		        money:""
			}
		},
		created(){
		    this.createNative();
		},
		methods:{
		    createNative(){
		        let orderId = getQueryString("orderId");
		        axios.get(`/wxpay/createNative?orderId=${orderId}`).then( response=>{
		            if( response.data.out_trade_no!=null ){
		                //生成二维码
                        let qrcode = new QRCode(document.getElementById("qrcode"), {
                            width : 200,
                            height : 200
                        });
                        qrcode.makeCode(response.data.code_url);
                        this.orderId=response.data.out_trade_no;
                        this.money= response.data.total_fee ;
						money= response.data.total_fee;
					}else{
		                location.href='payfail.html';//跳转到错误页
					}
				});
			}
		}
	});

	let money=0;
    let client = Stomp.client('ws://localhost:15674/ws');
    let on_connect = function(x) {
        id = client.subscribe("/exchange/paynotify", function(d) {
            if(d.body== getQueryString("orderId")){
                location.href="paysuccess.html?money="+money;
			}
        });
    };
    let on_error =  function() {
        console.log('error');
    };
    client.connect('webguest', 'itcast', on_connect, on_error, '/');

</script>


</body>

</html>